Ext.define('PrjAPLean.view.paapply.PaApplyPanelViewController', {
	extend : 'Ext.app.ViewController',
	alias : 'controller.paapplyvc',
	control : {
		'#' : {
			afterrender: 'onWinShow'
		}
	},
	onWinShow : function (win){
		var paForm = this.getView().down('form');
		var paId = paForm.getValues().id;
		if (paId == -1) {
			/*paContro.initPa( {'id' : paId},function(result) {
				if (result != null) {
					var leanProjectModel = Ext.create('PrjAPLean.model.LeanProject');
					leanProjectModel.data = result;
					paForm.loadRecord(leanProjectModel);
				}
			});*/
		} else {
			paContro.findPaById( {'id' : paId}, function(result) {
				if (result != null) {
					var leanProjectModel = Ext.create('PrjAPLean.model.LeanProject');
					leanProjectModel.data = result;
					paForm.loadRecord(leanProjectModel);
				}
			});
		}
	},
	onPanelClose: function(){
		/*var paId = this.getView().down('form').getValues().id;
		Ext.Msg.confirm('提示','确认放弃此次PA申请吗？',function(button){
			if(button == "yes"){
				paContro.deletePa( {'id' : paId});
				win.close();
			}
		});*/
	},
	onStartYearChange: function(como, newValue, oldValue){	
		var endYearCbo = this.getView().down('#endYear');
		endYearCbo.setValue(newValue);
	},
	onStartMmChange: function(como, newValue, oldValue){	
		var endMmCbo = this.getView().down('#endMm');
		var endMmStore = endMmCbo.getStore();
		endMmStore.clearFilter();  
		if (oldValue != null) {
			endMmCbo.clearValue();
		}
		endMmStore.filterBy(function(record) {
			return record.get('id') >= newValue;  
		});  
		endMmStore.reload();
	},
	onAddActivityClick: function(){
		var paId = this.getView().down('#id').getValue();
		var activityGroupId = this.getView().down('#activityGroupId').getValue();
		var channelId = this.getView().down('#channelId').getValue();
		var par = {
			'paId' : paId,
			'activityGroupId':activityGroupId,
			'channelId':channelId
		};
		paContro.addLeanProjectLine(par);
		var activityGridStore = this.getView().down('#activityGrid').getStore();
		activityGridStore.reload();
	}
});
